/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.manchester.biology.eqhei.persistence;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author mlwyatt
 */
@Entity
@Table(name = "Evaluation")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Evaluation.findAll", query = "SELECT e FROM Evaluation e"),
    @NamedQuery(name = "Evaluation.findByUtm", query = "SELECT e FROM Evaluation e WHERE e.evaluationPK.utm = :utm"),
    @NamedQuery(name = "Evaluation.findByUserName", query = "SELECT e FROM Evaluation e WHERE e.evaluationPK.userName = :userName"),
    @NamedQuery(name = "Evaluation.findByEvaluationTime", query = "SELECT e FROM Evaluation e WHERE e.evaluationPK.evaluationTime = :evaluationTime"),
    @NamedQuery(name = "Evaluation.findBySectionName", query = "SELECT e FROM Evaluation e WHERE e.evaluationPK.sectionName = :sectionName")})
public class Evaluation implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected EvaluationPK evaluationPK;
    @JoinColumn(name = "userName", referencedColumnName = "userName", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "UTM", referencedColumnName = "UTM", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private StreamReach streamReach;
    @OneToMany(mappedBy = "evaluation")
    private Collection<EvaluationSection> evaluationSectionCollection;

    public Evaluation() {
    }

    public Evaluation(EvaluationPK evaluationPK) {
        this.evaluationPK = evaluationPK;
    }

    public Evaluation(String utm, String userName, Date evaluationTime, String sectionName) {
        this.evaluationPK = new EvaluationPK(utm, userName, evaluationTime, sectionName);
    }

    public EvaluationPK getEvaluationPK() {
        return evaluationPK;
    }

    public void setEvaluationPK(EvaluationPK evaluationPK) {
        this.evaluationPK = evaluationPK;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public StreamReach getStreamReach() {
        return streamReach;
    }

    public void setStreamReach(StreamReach streamReach) {
        this.streamReach = streamReach;
    }

    @XmlTransient
    public Collection<EvaluationSection> getEvaluationSectionCollection() {
        return evaluationSectionCollection;
    }

    public void setEvaluationSectionCollection(Collection<EvaluationSection> evaluationSectionCollection) {
        this.evaluationSectionCollection = evaluationSectionCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (evaluationPK != null ? evaluationPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Evaluation)) {
            return false;
        }
        Evaluation other = (Evaluation) object;
        if ((this.evaluationPK == null && other.evaluationPK != null) || (this.evaluationPK != null && !this.evaluationPK.equals(other.evaluationPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.manchester.biology.eqhei.business.Evaluation[ evaluationPK=" + evaluationPK + " ]";
    }
    
}
